import requests


def baidu_translate(word):
    url = 'https://fanyi.baidu.com/sug'

    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
    }

    data = {
        'kw': word
    }

    try:
        response = requests.post(url, data=data, headers=headers)
        response.encoding = 'utf-8'
        result = response.json()

        if result.get('errno') == 0 and result.get('data'):
            print("\n翻译结果：")
            for item in result['data']:
                print(f"- {item['v']}")
        else:
            print("未找到相关翻译。")
    except Exception as e:
        print(f"请求过程中发生错误: {e}")


if __name__ == '__main__':
    user_input = input("请输入需要翻译的内容：")
    baidu_translate(user_input)